// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: PpaWirings.java 193 2005-08-16 07:15:32Z richetl $	
//

import java.io.*;
import java.util.*;

class PpaWirings
{

    class Wiring 
    {
	private String srcName;
	private String srcExit;
	private String dest;
	private String srcType;

	public String getSrcName() {
	    return srcName;
	}
	public void setSrcName(String s) {
	    srcName = s;
	}
	public String getSrcExit() {
	    return srcExit;
	}
	public void setSrcExit(String s) {
	    srcExit = s;
	}
	public String getDest() {
	    return dest;
	}
	public void setDest(String s) {
	    dest = s;
	}
	public void setSrcType(String s) {
	    srcType = s;
	}
	public void print(PrintStream file) {
	    if(srcName.equals("eth0")) {
		file.println("\tmakeConnection(\"" + srcName + 
			     "\", lee::NetInterface::" + 
			     srcExit.toUpperCase() + ", \"" + dest + "\");");
	    }
	    else if(srcName.equals("eth1")) {
		file.println("\tmakeConnection(\"" + srcName + 
			     "\", lee::NetInterface::" + 
			     srcExit.toUpperCase() + ", \"" + dest + "\");");
	    }
	    else if(srcName.equals("eth2")) {
		file.println("\tmakeConnection(\"" + srcName + 
			     "\", lee::NetInterface::" + 
			     srcExit.toUpperCase() + ", \"" + dest + "\");");
	    }
	    else if(srcName.equals("eth3")) {
		file.println("\tmakeConnection(\"" + srcName + 
			     "\", lee::NetInterface::" + 
			     srcExit.toUpperCase() + ", \"" + dest + "\");");
	    }
	    else {
		file.println("\tmakeConnection(\"" + srcName + "\", userPPF::" +
			     srcType + "::" + 
			     srcExit.toUpperCase() + ", \"" + dest + "\");");
	    }
	}
    }

    private LinkedList wiringList;
    private HashMap env;

    public PpaWirings() {
	wiringList = new LinkedList();
	env = null;
    }

    public void print(PrintStream file) {
	Iterator wirings = wiringList.iterator();
	int listSize = wiringList.size();
	for(int i = 0; i < listSize; i++) {
	    Wiring wiring = (Wiring)wirings.next();
	    wiring.print(file);
	}
	file.println();
    }

    public void addWiring(Wiring w) {
	wiringList.addLast(w);
    }

    public void setEnv(HashMap e) {
	env = e;
	Iterator wirings = wiringList.iterator();
	int listSize = wiringList.size();
	for(int i = 0; i < listSize; i++) {
	    Wiring wiring = (Wiring)wirings.next();
	    wiring.setSrcType((String)env.get(wiring.getSrcName()));
	}
    }

}

